package com.xmread.cn.network;

import android.content.Context;
import com.google.gson.JsonSyntaxException;
import com.liuguang.framework.utils.AppUtils;
import com.xmread.cn.bean.CommonResult;

import io.reactivex.rxjava3.core.Observer;


public abstract class ResponceSubscriber<T> implements Observer<CommonResult<T>> {
    private Context mContext;

    public void onComplete() {
    }

    /* access modifiers changed from: protected */
    public void onFail(String str) {
    }

//    public void onSubscribe(Disposable disposable) {
//    }

    /* access modifiers changed from: protected */
    public abstract void onSucess(T t);

    /* access modifiers changed from: protected */
    public boolean showDialog() {
        return true;
    }

    public ResponceSubscriber(Context context, String str, String str2) {
        this.mContext = context;
    }

    public ResponceSubscriber(Context context, String str) {
        this(context, null, str);
    }

    public ResponceSubscriber(Context context) {
        this(context, "请稍后……");
    }

    public ResponceSubscriber() {
        this.mContext = AppUtils.getApplication();
    }

    public void onNext(CommonResult<T> commonResult) {
        if (commonResult.getCode() == 200 || commonResult.getCode() == 1) {
            onSucess(commonResult.getData());
        } else {
            onFail(commonResult.getMsg());
        }
    }

    public void onError(Throwable th) {
        th.printStackTrace();
        if (!RFNetUtil.isNetworkConnected()) {
            onFail("网络不可用");
        } else if (th instanceof RuntimeException) {
            onFail(th.getMessage());
        } else if (th instanceof JsonSyntaxException) {
            onFail("数据解析异常");
        } else if (th instanceof NullPointerException) {
            onFail(th.getMessage());
        } else {
            onFail("请求失败，请稍后再试...");
        }
    }
}
